package za.co.sbi.sbiexam.service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DatabaseHelper {

	private static Connection connection = null;

	public static ResultSet select(String query) throws SQLException, ClassNotFoundException {
		getConnection();
		return connection.createStatement().executeQuery(query);
	}

	public static int delete(String query) throws SQLException, ClassNotFoundException {
		getConnection();
		return connection.createStatement().executeUpdate(query);
	}

	static int update(String query) throws SQLException, ClassNotFoundException {
		getConnection();
		return connection.createStatement().executeUpdate(query);
	}

	private static void getConnection() throws SQLException, ClassNotFoundException {
		if (connection == null) {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection("jdbc:mysql://localhost/sbiexam", "sbiexam", "123sbie");
		}
	}
}
